package com.gitee.feizns.quickstart.dict.spring.boot.autoconfigure.db.mybatis.flex.mapper;

import com.gitee.feizns.quickstart.dict.Entry;
import com.gitee.feizns.quickstart.dict.spring.boot.autoconfigure.db.mybatis.flex.pojo.QkDict;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.activerecord.Model;
import com.mybatisflex.core.query.QueryChain;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

import javax.persistence.Entity;
import java.util.List;

/**
 * qk dict 映射器
 * @author feizns
 * @since 2024/12/20
 */
@Mapper
@ConditionalOnClass({Entity.class, Model.class})
public interface QkDictMapper extends BaseMapper<QkDict> {

    /**
     * 查找全部
     * @return {@link List}<{@link Entry}>
     */
    static List<QkDict> findAll() {
        return new QkDict().list();
    }

    /**
     * 按键查找
     * @param key 钥匙
     * @return {@link QkDict}
     */
    default QkDict findByKey(String key) {
        return new QkDict().where(QkDict::getKey).eq(key).one();
    }

    /**
     * 键
     * @param key 钥匙
     * @return {@link QkDict}
     */
    static QkDict staticFindByKey(String key) {
        return QueryChain.of(QkDict.class).eq(QkDict::getKey, key).one();
    }

    /**
     * 存在键
     * @param key {@link String}
     * @return {@link Boolean}
     */
    static boolean staticExistKey(String key) {
        return QueryChain.of(QkDict.class).eq(QkDict::getKey, key).exists();
    }

}
